import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.*;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.ArrayList;


public class Main extends Application {
    public static ArrayList<Staff> staffList;
    @Override
    public void start(Stage stage) throws Exception {
        AnchorPane pane = new AnchorPane();
        Scene scene = new Scene(pane);
        stage.setScene(scene);
        stage.setTitle("登录");
        pane.setPrefSize(700, 600);
       Label label1 = new Label("账户:");
       Label label2 = new Label("密码:");
       Button button1 = new Button("登录");
       TextField textField1 = new TextField();
       TextField textField2 = new TextField();
       pane.getChildren().add(button1);
       pane.getChildren().add(label1);
       pane.getChildren().add(label2);
       pane.getChildren().add(textField1);
       pane.getChildren().add(textField2);
       pane.setTopAnchor(button1,Double.valueOf(400.0));
       pane.setLeftAnchor(button1,Double.valueOf(350.0));
       pane.setTopAnchor(label1,Double.valueOf(150.0));
       pane.setLeftAnchor(label1,Double.valueOf(250.0));
       pane.setTopAnchor(label2,Double.valueOf(250.0));
       pane.setLeftAnchor(label2,Double.valueOf(250.0));
       pane.setTopAnchor(textField1,Double.valueOf(165.0));
       pane.setLeftAnchor(textField1,Double.valueOf(280.0));
       pane.setTopAnchor(textField2,Double.valueOf(265.0));
       pane.setLeftAnchor(textField2,Double.valueOf(280.0));
       button1.setPrefSize(80, 60);
       label1.setPrefSize(60, 50);
       label2.setPrefSize(60, 50);
       stage.show();
       button1.setOnAction(e -> {
         String s1=textField1.getText();
         String s2=textField2.getText();
         if(s1.equals(NameAndPassword.getName())&&s2.equals(NameAndPassword.getPassword())){
            stage.close();
            LoginS();
         }
         else{
             stage.close();
             LoginF();
         }
       });
    }

//------------------------------------------------------------------------
    public static void main(String[] args) {
        staffList=new ArrayList<>();
        try {
            GETRESOURCE.GetResource();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        launch(args);
    }
 //---------------------------------------------------------------------------
    public void LoginS() {
        GridPane controlpane = new GridPane();
        controlpane.setPrefSize(825, 625);
        controlpane.setHgap(15);
        controlpane.setVgap(45);
        Scene conscene = new Scene(controlpane);
        Stage constage = new Stage();
        constage.setScene(conscene);
        constage.setTitle("员工管理系统");
        Button logoutButton = new Button("退出系统");
        Button SearchButton = new Button("查找员工信息");
        Button AddButton = new Button("添加员工");
        Button EditButton = new Button("编辑员工信息");
        Button DeleteButton = new Button("删除员工信息");
        Button BrowseButton = new Button("浏览员工");
        controlpane.add(logoutButton, 35, 0);
        logoutButton.setPrefSize(130, 60);
        controlpane.add(SearchButton, 1, 1);
        SearchButton.setPrefSize(130, 60);
        controlpane.add(AddButton, 1, 3);
        AddButton.setPrefSize(130, 60);
        controlpane.add(EditButton, 1, 5);
        EditButton.setPrefSize(130, 60);
        controlpane.add(DeleteButton, 1, 7);
        DeleteButton.setPrefSize(130, 60);
        controlpane.add(BrowseButton, 1, 9);
        BrowseButton.setPrefSize(130, 60);
        constage.show();
//-----------------------------------------------------------
        logoutButton.setOnAction(e -> {
            try {
                SAVERESOURCE.SaveResource();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
            constage.close();
        });
        SearchButton.setOnAction(e -> {
            Contronller.Search();
        });
        AddButton.setOnAction(e -> {
            Contronller.Add();
        });
        EditButton.setOnAction(e -> {
            Contronller.Edit();
        });
        DeleteButton.setOnAction(e -> {
            Contronller.Delete();
        });
        BrowseButton.setOnAction(e -> {
            Contronller.Browse();
        });}

        void LoginF () {
            BorderPane pane1 = new BorderPane();
            Scene scene1 = new Scene(pane1, 400, 300);
            Stage stage1 = new Stage();
            stage1.setScene(scene1);
            Label label3 = new Label("输入的账号或密码不正确");
            label3.setPrefSize(300, 150);
            pane1.setCenter(label3);
            Button button3 = new Button("确定");
            pane1.setBottom(button3);
            pane1.setPrefSize(200, 150);
            stage1.show();
            button3.setOnAction(e -> {
                stage1.close();
                try {
                    start(new Stage());
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            });
    }
}
